var t = getApp();

Page({
    data: {
        show1: !1,
        show2: !1,
        show3: !1,
        show4: !1,
        show5: !1,
        addressName: "",
        districtVal: "",
        popAddAddress: !1,
        strShow: !1,
        openDateLw: !1,
        provinceData: [],
        cityData: [],
        districtData: [],
        pickerValue: [ 0, 0, 0 ],
        selectAddressData: [],
        streetShow: !1,
        form: {
            name: "",
            telephoneNumber: "",
            addressContent: "",
            provinceId: "",
            cityId: "",
            districtId: "",
            address: "",
            streetId: null,
            remarksContent: "",
            checked: ""
        },
        agreementData: "",
        status: 1,
        banner: "",
        condition: "",
        showBuyGoods: !1,
        showBuyGoodslist: {},
        currentWordNumber: 0,
        clickTag: !1
    },
    telephoneInp: function(t) {
        var a = t.detail.value;
        this.setData({
            "form.telephoneNumber": a
        });
    },
    nameinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "form.name": a
        });
    },
    streetChoose: function() {
        t._isTextEmpty(this.data.addressName) ? wx.showToast({
            icon: "none",
            title: "请先选择所在地区",
            duration: 1500
        }) : this.setData({
            streetShow: !0
        });
    },
    openDateLwtbtn: function() {
        this.setData({
            openDateLw: !0
        });
    },
    onLoad: function(t) {},
    show1CloseBtn: function() {
        this.setData({
            show1: !1
        });
    },
    verifyApplyStatus: function() {
        var a = this, e = t.getNetAddresss("plugin.room.frontend.room.verifyApplyStatus");
        t._postNetWork({
            url: e,
            showToastIn: !1,
            data: {
                validate_page: 1
            },
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var s = e.data.status;
                    a.setData({
                        agreementData: e.data.agreement,
                        banner: e.data.banner
                    }), a.setData({
                        status: s
                    }), 2 == s && a.setData({
                        show3: !0
                    }), 3 == s && a.setData({
                        show5: !0,
                        condition: e.data.condition
                    }), 4 == s && a.setData({
                        show3: !0
                    }), 5 == s && a.setData({
                        show1: !0
                    }), 6 == s && wx.showModal({
                        title: "提示",
                        content: "您需要购买指定的商品才能申请主播！",
                        success: function(t) {
                            t.confirm ? a.setData({
                                showBuyGoodslist: e.data.goods,
                                showBuyGoods: !0
                            }) : t.cancel && (console.log("用户点击取消"), wx.reLaunch({
                                url: "/packageG/member_v2/member_v2"
                            }));
                        }
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    closedBuyGoodsPopup: function() {
        try {
            wx.navigateBack({
                delta: 1
            });
        } catch (t) {
            wx.reLaunch({
                url: "/packageG/member_v2/member_v2"
            });
        }
    },
    gotoGoods: function(t) {
        this.setData({
            showBuyGoods: !1
        });
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    goEditMobile: function() {
        wx.navigateTo({
            url: "/packageA/member/editmobile/editmobile?anchorApply=1"
        });
    },
    goLiveList: function() {
        wx.navigateTo({
            url: "/packageD/directSeeding/liveList/liveList"
        });
    },
    goExtensionApply: function() {
        wx.navigateTo({
            url: "/packageA/member/extension/ExtensionApply/ExtensionApply"
        });
    },
    goStoreApply: function() {
        wx.navigateTo({
            url: "/packageA/member/storeApply/storeApply"
        });
    },
    goSupplier: function() {
        wx.navigateTo({
            url: "/packageA/member/supplier/supplier"
        });
    },
    gohotel: function() {
        wx.navigateTo({
            url: "/packageA/member/storeApply/storeApply?name=hotelApply"
        });
    },
    _initAddressInfo: function() {
        var a = this;
        wx.getStorage({
            key: "provinceData",
            success: function(t) {
                console.log("地址信息准备就绪"), a._getProvinceData();
            },
            fail: function(e) {
                console.log("省fail"), t._getNetWork({
                    url: t.getNetAddresss("member.member-address.address"),
                    success: function(t) {
                        var e = t.data, s = e.data.province, o = e.data.city, i = e.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: s
                        }), wx.setStorage({
                            key: "cityData",
                            data: o
                        }), wx.setStorage({
                            key: "districtData",
                            data: i
                        }), a._initAddressInfo();
                    },
                    fail: function(t) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("省读取成功", a.data), t.setData({
                    provinceData: a.data
                }), t.setData({
                    "selectAddressData[0].name": a.data[t.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": a.data[t.data.pickerValue[0]].id,
                    "selectAddressData[0].index": t.data.pickerValue[0]
                }), t._getCityData();
            }
        });
    },
    _getCityData: function() {
        var t = this.data.selectAddressData[0];
        console.log("城市", "_data", t);
        var a = this;
        wx.getStorage({
            key: "cityData",
            success: function(e) {
                console.log("城市读取成功", e);
                for (var s = [], o = 0; o < e.data.length; o++) e.data[o].parentid == t.id && s.push(e.data[o]);
                console.log("城市数据筛选", s), a.setData({
                    cityData: s
                }), a.setData({
                    "selectAddressData[1].name": s[a.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": s[a.data.pickerValue[1]].id,
                    "selectAddressData[1].index": a.data.pickerValue[1]
                }), a._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var t = this.data.selectAddressData[1];
        console.log("地区", "_data", t), console.log(t);
        var a = this;
        wx.getStorage({
            key: "districtData",
            success: function(e) {
                console.log("地区读取成功");
                for (var s = [], o = 0; o < e.data.length; o++) e.data[o].parentid == t.id && s.push(e.data[o]);
                console.log("地区数据筛选", s), a.setData({
                    districtData: s
                }), console.log("districtData", s), a.setData({
                    "selectAddressData[2].name": s[a.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": s[a.data.pickerValue[2]].id,
                    "selectAddressData[2].index": a.data.pickerValue[2]
                }), console.log("over", a.data.selectAddressData);
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        this.setData({
            show1: !1,
            show2: !1,
            show3: !1,
            show4: !1,
            show5: !1
        }), this.verifyApplyStatus(), this._initAddressInfo();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    bindChange: function(t) {
        var a = t.detail.value;
        this.data.pickerValue[0] != a[0] && (a[1] = 0, a[2] = 0), this.data.pickerValue[1] != a[1] && (a[2] = 0), 
        this.setData({
            "pickerValue[0]": a[0],
            "pickerValue[1]": a[1],
            "pickerValue[2]": a[2]
        }), this._initAddressInfo();
    },
    _closeDateLw: function() {
        this.setData({
            openDateLw: !1
        });
    },
    _okAddress: function() {
        var t = this.data.selectAddressData, a = t[0].name + " " + t[1].name + " " + t[2].name, e = t[0].id, s = t[1].id, o = t[2].id;
        this.setData({
            addressName: a,
            "form.provinceId": e,
            "form.cityId": s,
            "form.districtId": o
        }), this._getStreet(t[2].id), this._closeDateLw();
    },
    _getStreet: function(a) {
        var e = this, s = t.getNetAddresss("member.memberAddress.street");
        s += "&district_id=" + a, t._getNetWork({
            url: s,
            success: function(a) {
                var s = a.data;
                1 != s.result || t._isTextEmpty(s.data) ? e.setData({
                    strShow: !1
                }) : !t._isTextEmpty(s.data) && s.data.length > 0 ? e.setData({
                    districtVal: s.data,
                    strShow: !0
                }) : e.setData({
                    strShow: !1
                });
            },
            fail: function(t) {
                e.setData({
                    strShow: !1
                }), console.log(t);
            }
        });
    },
    streetConfirm: function(t) {
        var a = t.target.dataset.strname, e = t.target.dataset.strid;
        this.setData({
            "form.street": a,
            "form.streetId": e,
            streetShow: !1,
            opren: !0
        });
    },
    streetClose: function() {
        this.setData({
            streetShow: !1,
            opren: !0
        });
    },
    addressInp: function(t) {
        var a = t.detail.value;
        this.setData({
            "form.addressContent": a
        });
    },
    remarksInp: function(t) {
        var a = t.detail.value, e = parseInt(a.length);
        this.setData({
            "form.remarksContent": a,
            currentWordNumber: e
        });
    },
    protocolBtn: function(t) {
        var a = t.detail;
        this.setData({
            "form.checked": a
        });
    },
    openProtocol: function() {
        this.setData({
            show4: !0
        });
    },
    show4CloseBtn: function() {
        this.setData({
            show4: !1
        });
    },
    submit: function() {
        if (!this.data.clickTag) {
            var a = this;
            if (!this.data.form.name) return wx.showToast({
                title: "请输入您的姓名",
                icon: "none",
                duration: 1500
            }), !1;
            if (!this.data.form.telephoneNumber) return wx.showToast({
                title: "手机号不能为空",
                icon: "none",
                duration: 1500
            }), !1;
            if (this.data.form.telephoneNumber && t._isMoblie(this.data.form.telephoneNumber)) return wx.showToast({
                title: "请输入正确的手机号",
                icon: "none",
                duration: 1500
            }), !1;
            if (!this.data.addressName) return wx.showToast({
                title: "请选择收货地址",
                icon: "none",
                duration: 1500
            }), !1;
            if (!this.data.form.streetId && 0 != this.data.form.streetId && this.data.strShow) return wx.showToast({
                title: "请选择街道",
                icon: "none",
                duration: 1500
            }), !1;
            if (!this.data.form.addressContent) return wx.showToast({
                title: "请填写详细的地址",
                icon: "none",
                duration: 1500
            }), !1;
            if (!this.data.form.checked) return wx.showToast({
                title: "请勾选用户协议",
                icon: "none",
                duration: 1500
            }), !1;
            a.setData({
                clickTag: !0
            });
            var e = t.getNetAddresss("plugin.room.frontend.room.apply");
            t._postNetWork({
                url: e,
                showToastIn: !1,
                data: {
                    realname: this.data.form.name,
                    mobile: this.data.form.telephoneNumber,
                    provinceId: this.data.form.provinceId,
                    cityId: this.data.form.cityId,
                    districtId: this.data.form.districtId,
                    streetId: this.data.form.streetId,
                    address: this.data.form.addressContent,
                    remark: this.data.form.remarksContent
                },
                success: function(t) {
                    var e = t.data;
                    if (a.setData({
                        clickTag: !0
                    }), 1 == e.result) {
                        if ("" != e.data.jump_min_url && null != e.data.jump_min_url && null != e.data.jump_min_url) try {
                            return void wx.navigateTo({
                                url: e.data.jump_min_url
                            });
                        } catch (t) {
                            console.log(t);
                        }
                        a.setData({
                            show2: !0
                        });
                    } else wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    }
});